﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Messaging.Senders;
using System.Net.Mail;
using Messaging.Config;

namespace Messaging.Services
{
    public class EmailService : IEmailService
    {
        IMessageSender _sender = new MessageSender();

        public void Send(string body, string subject, string[] to, AttachmentCollection attachments = null)
        {
            foreach (var toOne in to)
                Send(body, subject, toOne, attachments);
        }

        public void Send(string body, string subject, string to, AttachmentCollection attachments = null)
        {
            MailMessage message = new MailMessage();
            message.Body = body;
            message.IsBodyHtml = true;
            message.Subject = subject;
            message.To.Add(new MailAddress(to));
            message.From = new MailAddress(SMTPConfig.SmtpUserName, SMTPConfig.SmtpDisplayName);
            if (attachments != null)
            {
                foreach (var attach in attachments)
                    message.Attachments.Add(attach);
            }

            _sender.Send(message);
        }
    }
}
